import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:不相邻数之和
 * User: wangxin
 * Date: 2024-09-25
 * Time: 17:40
 */
public class test2 {
    public static long add(long[] a){

        int n = a.length;
        if(a.length == 1){
            return a[0];
        }
        if(a.length == 2){
            return a[0] > a[1]?a[0]:a[1];
        }
        long[] dp = new long[n];
        dp[0] = a[0];
        dp[1] = a[1];
        dp[2] = a[0]+a[2];
        for(int i=3;i<dp.length;i++){
            dp[i] = a[i]+(dp[i-2]>dp[i-3]?dp[i-2]:dp[i-3]);
        }
        return(dp[n-1]>dp[n-2]?dp[n-1]:dp[n-2]);


    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别

        int n = in.nextInt();
        long[] a = new long[n];
        for(int i = 0;i < n;i++){
            a[i] = in.nextInt();
        }
        long ret = add(a);
        System.out.println(ret);

    }
}
